package com.zm.vcode;

import com.zm.vcode.bean.VcodeProperties;
import com.zm.vcode.web.VcodeInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@ComponentScan("com.zm.vcode")
@Slf4j
@ConditionalOnProperty(prefix = "vcode",name = "enable",havingValue = "true")
public class VcodeConfig implements WebMvcConfigurer {

    @Autowired
    VcodeProperties properties;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new VcodeInterceptor())
                .addPathPatterns(properties.getPaths());
    }
}
